class LinkController < ApplicationController

  def save
    Link.transaction do
      link = Link.create!(:from => Location.adapt(params[:data][:from]),
        :to => Location.adapt(params[:data][:to]),
      :grid => @grid)
    data = {:data => ['itemsLinkedEvent', link.to_hash]}.to_json
    GridEvent.create(:data => data, :grid => @grid, :users => @users)
    head :ok  
    end
  end

  def destroy
    Link.transaction do
      Link.destroy_at_locations(params[:data][:location1], params[:data][:location2])
      data = {:data => ['itemsUnlinkedEvent', params[:data]]}.to_json
      GridEvent.create(:data => data, :grid => @grid, :users => @users)
      head :ok
    end
  end

end
